#include "stdio.h"
#include "../section_locate.h"

#include "pt-thread.h"

void pt_completion_test(void);

static char name[30] = "pt_completion_test";
struct func_pack sec_pt_completion_test __attribute__ ( ( section ( "func_area" ) ) ) = {
    .func_addr = pt_completion_test,
	.name_str = (uint32_t *)&name,
};


struct pt pt4;

#include "completion.h"
struct pt_completion timer1_complete;
static PT_THREAD( entry4(struct pt *pt) )
{
    PT_BEGIN ( pt );
    pt_completion_init(&timer1_complete);
    printf("entry4\n");

    while(1){

//        if( PT_EOK == pt_completion_wait(&timer1_complete) ){
//            printf("complete\n");
//        }
//        PT_COMPLET_WAIT_F(&timer1_complete);
        static int res;
        res = PT_COMPLET_WAIT_TO(&timer1_complete, 100);
        if(res == PT_EOK){
            printf("complete\n");

        }else{
            printf("time out\n");
        }

//        PT_YIELD(pt);

    }

    PT_END( pt );
}

static void test_timer1_cb(void *parameter);
struct timer test_timer1;



void pt_completion_test(void)
{






    pt_thread_init(&pt4, entry4);

    pt_timer_init(&test_timer1, PT_NULL, test_timer1_cb, PT_NULL, 464, PT_TIMER_FLAG_PERIODIC);

    pt_timer_start(&test_timer1);


    pt_god_schedule();
}

static void test_timer1_cb(void *parameter)
{
    (void)parameter;
    printf("test_timer1_cb\n");
    pt_completion_done(&timer1_complete);
}



